package com.gitee.wsl.mathematics.function


/**
 * Calculates the greatest common divisor (GCD) of the two integers in the Pair.
 *
 * @receiver The Pair of integers.
 * @return The greatest common divisor of the two integers.
 */
fun Pair<Int, Int>.gcd(): Int {
    var largerNumber = first
    var smallerNumber = second
    while (smallerNumber != 0) {
        val remainder = largerNumber % smallerNumber
        largerNumber = smallerNumber
        smallerNumber = remainder
    }
    return largerNumber
}

/**
 * Calculates the greatest common divisor (GCD) of two integers.
 *
 * @param number1 The first integer.
 * @param number2 The second integer.
 * @return The greatest common divisor of the two integers.
 */
fun gcd(
    number1: Int,
    number2: Int
): Int = if (number2 == 0) number1 else gcd(number2, number1 % number2)
